package org.trade.goods.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.trade.common.api.IGoodsApi;
import org.trade.common.constant.TradeEnums;
import org.trade.common.protocol.goods.QueryGoodsReq;
import org.trade.common.protocol.goods.QueryGoodsRes;
import org.trade.common.protocol.goods.ReduceGoodsNumberReq;
import org.trade.common.protocol.goods.ReduceGoodsNumberRes;
import org.trade.goods.service.IGoodsService;


@Controller
public class GoodsApiImpl implements IGoodsApi{
    @Autowired
	private IGoodsService goodsService;
    
	@RequestMapping(value="/queryGoods",method=RequestMethod.POST)
	@ResponseBody
	public QueryGoodsRes queryGoods(@RequestBody QueryGoodsReq queryGoodsReq) {
		
		return this.goodsService.queryGoods(queryGoodsReq);
	}
	
	@ResponseBody
	@RequestMapping(value="/reduceGoodsNumber",method=RequestMethod.POST)
	public ReduceGoodsNumberRes reduceGoodsNumber(@RequestBody ReduceGoodsNumberReq reduceGoodsNumberReq) {
		ReduceGoodsNumberRes reduceGoodsNumberRes=new ReduceGoodsNumberRes();
		try{
		 reduceGoodsNumberRes=this.goodsService.reduceGoodsNumber(reduceGoodsNumberReq);
		}catch (Exception e) {
			reduceGoodsNumberRes.setRetCode(TradeEnums.RetEnum.FAIL.getCode());
			reduceGoodsNumberRes.setRetInfo(e.getMessage());
		}
		 return reduceGoodsNumberRes;
	}

}
